package com.wu.web;

import com.alibaba.fastjson.JSON;
import com.wu.bean.Journal;
import com.wu.model.JournalModel;
import com.wu.service.JournalService;
import com.wu.service.impl.JournalServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 返回日志表的所有数据
 */
@WebServlet("/QueryAllLogsServlet")
public class QueryAllLogsServlet extends HttpServlet {
    @Override

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        JournalService journalService = new JournalServiceImpl();
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        List<JournalModel> journals = journalService.QueryLogAll();
        //转化为json格式

        String jsonstr= JSON.toJSON(journals).toString();
        resp.getWriter().print(jsonstr);
////list转换为json
//        List<CustPhone> list = new ArrayList<CustPhone>();
//        String str=JSON.toJSON(list).toString();
        //json转换为list
//        List<Person> list = new ArrayList<Person>();
//        list = JSONObject.parseArray(jasonArray, Person.class);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
